﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace ImageProccessingPractice
{
   public class GraySacler
    {
       /// <summary>
       /// Changing the image's color to gray 
       /// </summary>
       /// <param name="path">file path</param>
       /// <returns>the new gray image</returns>
        public static Bitmap Graying(String path)
        {
            Bitmap temp = new Bitmap(path);
            Bitmap workingOn = (Bitmap)temp.Clone();
            Color c;
            for (int i = 0; i < workingOn.Width; i++)
            {
                for (int j = 0; j < workingOn.Height; j++)
                {
                    c = workingOn.GetPixel(i, j);
                    byte gray = (byte)(0.235 * c.R + 0.590 * c.G + 0.175 * c.B);
                    workingOn.SetPixel(i, j, Color.FromArgb(gray, gray, gray));
                }
            }
            return (temp = (Bitmap)workingOn.Clone());
        }
       /// <summary>
        /// Transposing an image rotating it 90 degrees
       /// </summary>
       /// <param name="path">File Path</param>
       /// <returns>new transposed image</returns>
        public static Bitmap Transpose(String path)
        {
            Bitmap temp = new Bitmap(path);
            int h = temp.Width ;
            int w = temp.Height;
            Bitmap workingOn = new Bitmap(w, h);
            Color c;
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    c = temp.GetPixel(j, i);
                    workingOn.SetPixel(i, j, c);
                }
            }
            return workingOn;
        }
       

       /// <summary>
       /// Reverting the image
       /// </summary>
       /// <param name="path">file path</param>
       /// <returns>new reverted image</returns>
        public static Bitmap Revert(String path)
        {
            Bitmap temp = new Bitmap(path);
            int h1 = temp.Height-1;
            int w1 = temp.Width-1;
            Bitmap workingOn = new Bitmap(w1 + 1, h1 + 1);
            Color c;
            for (int i = 0; i < h1; i++)
            {
                for (int j = w1, w = 0; j >= 0; j--,w++)
                {
                    c = temp.GetPixel(j , i);
                    workingOn.SetPixel(w,i,c);
                    
                }
            }

            return workingOn;
        }
       /// <summary>
       /// Flipping top to bottom
       /// </summary>
       /// <param name="path">File path</param>
       /// <returns>flipped image</returns>
        public static Bitmap TopToBottom(String path)
        {
            Bitmap temp = new Bitmap(path);
            Bitmap workingOn = (Bitmap)temp.Clone();
            int h1 = temp.Height - 1;
            int w1 = temp.Width - 1;
            Color c;
            for (int i = w1, w = 0; i >= 0; i--, w++)
            {
                for (int j = h1, h = 0; j >= 0; j--, h++)
                {
                    c = temp.GetPixel(i, j);
                    workingOn.SetPixel(w, h, c);

                }
            }

            return workingOn;
        }
       /// <summary>
       /// reduce the size by half
       /// </summary>
       /// <param name="path">file path</param>
       /// <returns>half the size of the original image</returns>
        public static Bitmap cutInHalf(String path)
        {
            Bitmap temp = new Bitmap(path);
            int nW = temp.Width / 2;
            int nH = temp.Height / 2;
            Bitmap workingOn = new Bitmap(nW, nH);
            Graphics.FromImage(workingOn).DrawImage(temp, 0, 0, nW, nH);
            return workingOn;

        }



    }
}
